<template>
  <div style="width: 100%;height: 500px;padding-top:0;margin: 0 ">
    <div class="pageheader">
      <div class="pageheader-1">
        <i class="el-icon-user-solid"></i><label>慢性病报销</label>
      </div>
      <div style="height: 100%;position: absolute;top: 20px;left: 350px">
        <el-form :model="input" ref="key">
        <el-input
          style="width: 200px;position: absolute;top: 5px;left: 0px"
          size="small"
          placeholder="请输入农民的身份证号"
          suffix-icon="el-icon-search"
          maxlength="20"
          v-model="input.input3">
        </el-input>
        <el-button type="primary" v-show="list[1].children[4].find" class="searchbtn" @click="find('key')" plain>确定</el-button>
        </el-form>
      </div>
      <div class="left" v-show="left">
        <span class="spanone">农民信息</span>
        <el-form  :model="userform1" ref="editpeple">
          <el-form-item  label="姓名" :label-width="formLabelWidth">
            <label>{{userform1.name}}</label>
          </el-form-item>
          <el-form-item  label="性别" :label-width="formLabelWidth">
            <label>{{userform1.sex}}</label>
          </el-form-item>
          <el-form-item  label="身份证号" :label-width="formLabelWidth">
            <label>{{userform1.chengid}}</label>
          </el-form-item>
          <el-form-item  label="农合证号" :label-width="formLabelWidth">
            <label>{{userform1.nongid}}</label>
          </el-form-item>
          <el-form-item  label="参合发票" :label-width="formLabelWidth">
            <label>{{userform1.resig}}</label>
          </el-form-item>
          <el-form-item  label="参合时间" :label-width="formLabelWidth">
            <label>{{userform1.time}}</label>
          </el-form-item>
        </el-form>
      </div>
      <div class="right" v-show="right">
        <span class="spanone">录入报销信息</span>
        <el-form :rules="roles"  :model="userform" ref="userform">
          <el-form-item prop="baoxiaoid" label="报销编号" :label-width="formLabelWidth">
            <el-input  v-model="userform.baoxiaoid" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item prop="name" label="姓名" :label-width="formLabelWidth">
            <el-input  v-model="userform.name" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item prop="chronicname" label="疾病名称" :label-width="formLabelWidth">
            <el-input  v-model="userform.chronicname" autocomplete="off"></el-input>
          </el-form-item>
          <el-form-item prop="money" label="花费金额" :label-width="formLabelWidth">
            <el-input  v-model="userform.money" autocomplete="off"></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button v-show="list[1].children[4].showadd" type="primary" @click="check('userform')">提 交</el-button>
        </div>
      </div>
      <el-dialog
        title="提示"
        :visible.sync="openelete"
        width="30%"
        center>
        <span>您本次可报销的金额为{{baoxiaojin}}</span>
        <span slot="footer" class="dialog-footer">
    <el-button @click="openelete = false">取 消</el-button>
    <el-button type="primary" @click="delete_data" >确 定</el-button>
  </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  inject: ['reload', 'list'],
  methods: {
    // 查询农民是否参合
    find (key) {
      const _this = this
      if (this.input.input3 !== '') {
        axios.get('http://localhost:8088/findByChengid_B/' + this.input.input3).then(function (resp) {
          if (resp.data === '已参合') {
            _this.left = true
            _this.right = true
            axios.get('http://localhost:8088/findByChengid_B_F/' + _this.input.input3).then(function (resp1) {
              _this.userform1.name = resp1.data.chengname
              _this.userform1.canheid = resp1.data.canheid
              _this.userform1.chengid = resp1.data.chengid
              _this.userform1.sex = resp1.data.sex
              _this.userform1.nongid = resp1.data.nongid
              _this.userform1.resig = resp1.data.resig
              _this.userform1.time = resp1.data.chantime
            })
          } else {
            alert(resp.data)
          }
        })
      } else {
        this.reload()
      }
    },
    delete_data () {
      this.form.name = this.userform1.name
      this.form.chengid = this.userform1.chengid
      this.form.money = this.baoxiaojin
      this.form.status = '审核中'
      this.form.baoxiaoid = this.userform.baoxiaoid
      axios.post('http://localhost:8088/saveBaoxiao', this.form).then(function (resp) {
      })
      this.$message({
        message: '已提交',
        type: 'success'
      })
      this.reload()
    },
    // 验证信息是否合法
    check (userform) {
      const _this = this
      this.$refs[userform].validate((valid) => {
        axios.get('http://localhost:8088/testmsg/' + this.userform1.chengid + '/' + this.userform.chronicname + '/' + this.userform.money).then(function (resp) {
          if (resp.data === '当前时间不在报销时间范围内') {
            alert('当前时间不在报销时间范围内')
          } else if (resp.data === '该疾病与慢性病证中不一致') {
            alert('该疾病与慢性病证中不一致')
          } else if (resp.data === '报销余额不足') {
            alert('余额不足')
          } else {
            _this.baoxiaojin = resp.data
            _this.openelete = true
          }
        })
      })
    }
  },

  // 接受后台数据
  created () {
  },
  //  数据绑定
  data () {
    return {
      input: {
        input3: ''
      },
      left: false,
      right: false,
      formLabelWidth: 100,
      baoxiaojin: '',
      openelete: false,
      userform: {
        name: '',
        chronicname: '',
        money: '',
        baoxiaoid: ''
      },
      userform1: {
        name: '',
        chengid: '',
        sex: '',
        canheid: '',
        resig: '',
        time: ''
      },
      form: {
        id: '',
        baotime: '',
        baoxiaoid: '',
        money: '',
        name: '',
        status: '',
        chengid: ''
      },
      roles: {
        name: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        chronic: [
          { required: true, message: '慢性病名称不能为空', trigger: 'blur' }
        ],
        money: [
          { required: true, message: '花费金额不能为空', trigger: 'blur' }
        ],
        baoxiaoid: [
          { required: true, message: '报销编号不能为空', trigger: 'blur' }
        ]
      }
    }
  }
}
</script>
